package com.minstone.common.util;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

import org.apache.log4j.Logger;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

public class SystemConfigUtil extends PropertyPlaceholderConfigurer {
	
private final Logger logger = Logger.getLogger(SystemConfigUtil.class);
	
	private static final Map<String, String> propMap = new HashMap<String, String>();

	protected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props) {
		try {
			Set keySets = props.keySet();
			if ((keySets != null) && (keySets.size() != 0)) {
				this.logger.info("加载配置文件...");
			}

			for (Iterator it = keySets.iterator(); it.hasNext();) {
				Object key = it.next();
				String mapKey = key.toString();
				String mapVal = props.getProperty(mapKey);

				propMap.put(mapKey, mapVal);
			}
			System.out.println("\n" + propMap.toString());
			super.processProperties(beanFactoryToProcess, props);
		} catch (BeansException e) {
			logger.error("加载配置文件失败...", e);
		}
	}

	public static Map<String, String> getPropmap() {
		return propMap;
	}

}
